package com.ocm.tourism.core.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Version;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
public class SightSeeing {

   @OneToOne(cascade=CascadeType.ALL)
   private FileInfo avatar;

   @NotEmpty
   private String title;

   @Lob
   @org.hibernate.annotations.Type(type = "org.hibernate.type.TextType")
   private String content;

   @ManyToOne
   private Catalogues catalogues;

   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }

   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_SIGHTSEEING")
   @TableGenerator(name = "GEN_SIGHTSEEING", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "SIGHTSEEING")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   public String getContent() {
      return content;
   }

   public void setContent(String content) {
      this.content = content;
   }

   public FileInfo getAvatar() {
      return avatar;
   }

   public void setAvatar(FileInfo avatar) {
      this.avatar = avatar;
   }

   public Catalogues getCatalogues() {
      return catalogues;
   }

   public void setCatalogues(Catalogues catalogues) {
      this.catalogues = catalogues;
   }
   
   @Override
   public boolean equals(Object obj) {
      SightSeeing compare = (SightSeeing) obj;
      if (compare.getId()!=null && this.getId()!=null){
         return compare.getId().longValue() == this.getId().longValue();
      }
      return super.equals(obj);
   }
}
